package com.cg.asm.core.config.security;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Service
public class CustomPasswordEncoder extends BCryptPasswordEncoder {
    @Resource
    HttpServletRequest httpServletRequest;

    public boolean matches(CharSequence rawPassword, String encodedPassword) {
        String singleLogin  = httpServletRequest.getParameter("singleLogin");
        if ("true".equals(singleLogin)) {
            // 免密登陆
            String encodingPwd  = httpServletRequest.getParameter("encodingPwd");
            return super.matches(rawPassword, encodingPwd);
        }
        return super.matches(rawPassword, encodedPassword);
    }
}
